package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.ReplyDTO;
import com.sky.entity.Reply;
import com.sky.enumeration.OperationType;
import com.sky.vo.ReplyVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReplyMapper {
    /**
     * 新增回复
     * @param replyDTO
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("Insert into reply (comment_id, content, nickname, email, reply_to_id,reply_to_nickname,create_time, update_time)" +
            " values (#{commentId}, #{content}, #{nickname}, #{email}, #{replyToId},#{replyToNickname},#{createTime}, #{updateTime})")
    //主键回写
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addReply(ReplyDTO replyDTO);

    /**
     * 根据评论id查询回复列表
     * @param commentId
     * @return
     */
    @Select("select id, content, nickname, email, reply_to_id, reply_to_nickname, create_time from reply where comment_id = #{commentId}")
    List<ReplyVO> listReply(Long commentId);

    /**
     * 根据评论id删除回复
     * @param commentId
     */
    @Delete("delete from reply where comment_id = #{commentId}")
    void deleteReplyByCommentId(Long commentId);

    /**
     * 根据评论id查询回复
     * @param commentId
     * @return
     */
    @Select("select * from reply where comment_id = #{commentId}")
    List<ReplyVO> getReplyCommentId(Long commentId);
    

    /**
     * 根据评论id列表查询回复id列表
     * @param commentIds
     * @return
     */
    List<Long> getReplyIdsByCommentIds(List<Long> commentIds);

    /**
     * 根据回复id列表删除回复
     * @param replyIds
     */
    void deleteReplyByReplyIds(List<Long> replyIds);
}
